package smedi.ismedi.web.bff.controller.constructionproject;

import com.smedi.ismedi.constructionproject.api.dto.request.*;
import com.smedi.ismedi.constructionproject.api.dto.response.ProjectApplyResponse;
import com.smedi.ismedi.constructionproject.api.dto.response.ProjectAssignmentResponse;
import com.smedi.ismedi.constructionproject.api.dto.response.ProjectBasicResponse;
import com.smedi.ismedi.constructionproject.api.feign.RemoteProjectApplyFeignApi;
import com.smedi.ismedi.constructionproject.api.feign.RemoteProjectAssignmentFeignApi;
import com.smedi.ismedi.personnel.api.dto.response.PersonSimpleResponse;
import com.smedi.ismedi.personnel.api.feign.RemotePersonCoreFeignApi;
import com.smedi.ismedi.web.starter.common.PaginationData;
import com.smedi.ismedi.web.starter.common.ResponseData;
import com.smedi.ismedi.web.starter.exception.LogicException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import smedi.ismedi.web.bff.controller.BaseController;
import smedi.ismedi.web.bff.dto.PersonPickerResponse;
import smedi.ismedi.web.bff.infrastructure.constant.CustomError;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 项目分配接口
 *
 * @author xulinjun
 */
@Slf4j
@RestController
@Api(tags = {"项目申请接口"})
@RequestMapping("/webbff/v1/projectApply")
@AllArgsConstructor
public class ProjectApplyController extends BaseController {
    private final RemoteProjectApplyFeignApi remoteProjectApplyFeignApi;

    /**
     * 保存项目申请信息
     *
     * @param
     * @return
     */
    @ApiOperation(httpMethod = "POST", value = "保存项目申请信息")
    @PostMapping(value = "/save")
    ResponseData<ProjectApplyResponse> postSave(@Validated @RequestBody ProjectApplyCreateRequest projectApplyCreateRequest) {

        return remoteProjectApplyFeignApi.postSave(projectApplyCreateRequest);
    }

    /**
     * 编辑项目申请信息
     *
     * @param
     * @return
     */
    @ApiOperation(httpMethod = "POST", value = "编辑项目申请信息")
    @PostMapping(value = "/edit")
    ResponseData<ProjectApplyResponse> postEdit(@Validated @RequestBody ProjectApplyEditRequest projectApplyEditRequest) {

        return remoteProjectApplyFeignApi.postEdit(projectApplyEditRequest);
    }
    /**
     * 主体院分管领导审批 项目申请
     *
     * @param processInstituteLeaderApprovalRequest 主体院分管领导审批 项目申请
     * @return ResponseData<ProjectApplyResponse>
     */
    @ApiOperation(value = "主体院分管领导审批 项目申请", nickname = "主体院分管领导审批 项目申请")
    @PostMapping (value = "/project/institute-leader-approval")
    ResponseData<ProjectApplyResponse> instituteLeaderApproval(@Validated @RequestBody ProcessInstituteLeaderApprovalRequest processInstituteLeaderApprovalRequest){

        return remoteProjectApplyFeignApi.instituteLeaderApproval(processInstituteLeaderApprovalRequest);
    }
    /**
     * 工程部工程师审批 项目申请
     *
     * @param processEngineerApprovalRequest 工程部工程师审批 项目申请
     * @return ResponseData<ProjectApplyResponse>
     */
    @ApiOperation(value = "工程部工程师审批 项目申请", nickname = "工程部工程师审批 项目申请")
    @PostMapping (value = "/project/engineer-approval")
    ResponseData<ProjectApplyResponse> engineerApproval(@Validated @RequestBody ProcessEngineerApprovalRequest processEngineerApprovalRequest){

        return remoteProjectApplyFeignApi.engineerApproval(processEngineerApprovalRequest);
    }
    /**
     * 工程部分管领导审批 项目申请
     *
     * @param processEngineeringLeaderApprovalRequest 工程部分管领导审批 项目申请
     * @return ResponseData<ProjectApplyResponse>
     */
    @ApiOperation(value = "工程部分管领导审批 项目申请", nickname = "工程部分管领导审批 项目申请")
    @PostMapping (value = "/project/engineering-leader-approval")
    ResponseData<ProjectApplyResponse> engineeringLeaderApproval(@Validated @RequestBody ProcessEngineeringLeaderApprovalRequest processEngineeringLeaderApprovalRequest){

        return remoteProjectApplyFeignApi.engineeringLeaderApproval(processEngineeringLeaderApprovalRequest);
    }
    /**
     * 总院分管领导审批 项目申请
     *
     * @param processGeneralInstituteLeaderApprovalRequest 总院分管领导审批 项目申请
     * @return ResponseData<ProjectApplyResponse>
     */
    @ApiOperation(value = "总院分管领导审批 项目申请", nickname = "总院分管领导审批 项目申请")
    @PostMapping (value = "/project/general-institute-leader-approval")
    ResponseData<ProjectApplyResponse> generalInstituteLeaderApproval(@Validated @RequestBody ProcessGeneralInstituteLeaderApprovalRequest processGeneralInstituteLeaderApprovalRequest){

        return remoteProjectApplyFeignApi.generalInstituteLeaderApproval(processGeneralInstituteLeaderApprovalRequest);
    }
    /**
     * 获取 项目申请 列表
     *
     * @param projectApplyListRequest 项目申请 列表 请求
     * @return ResponseData<List<ProjectApplyResponse>>
     */
    @ApiOperation(value = "获取 项目申请 列表", nickname = "获取 项目申请 列表")
    @PostMapping (value = "/project-apply/list")
    ResponseData<List<ProjectApplyResponse>> getProjectApplyList(@Validated @RequestBody ProjectApplyListRequest projectApplyListRequest){

        return remoteProjectApplyFeignApi.getProjectApplyList(projectApplyListRequest);
    }

    /**
     * 获取 项目申请 分页
     *
     * @param projectApplyPageRequest 项目申请 分页 请求
     * @return ResponseData<PaginationData<ProjectApplyResponse>>
     */
    @ApiOperation(value = "获取 项目申请 分页", nickname = "获取 项目申请 分页")
    @PostMapping (value = "/project-apply/page")
    ResponseData<PaginationData<ProjectApplyResponse>> getProjectApplyPage(@Validated @RequestBody ProjectApplyPageRequest projectApplyPageRequest){

        return remoteProjectApplyFeignApi.getProjectApplyPage(projectApplyPageRequest);
    }
    /**
     * 获取 项目申请 恢复
     *
     * @param projectId 项目申请 恢复 请求
     * @return ResponseData<PaginationData<ProjectApplyResponse>>
     */
    @ApiOperation(value = "恢复", nickname = "恢复")
    @PostMapping (value = "/restore")
    ResponseData<Boolean> restoreProject(@RequestParam("projectId") Long projectId) {
        return remoteProjectApplyFeignApi.restoreProject(projectId);
    }
    /**
     * 获取 项目申请 详情
     *
     * @param id 项目申请 详情
     * @return ResponseData<PaginationData<ProjectApplyResponse>>
     */
    @ApiOperation(value = "详情", nickname = "详情")
    @GetMapping (value = "/detail")
    ResponseData<ProjectApplyResponse> projectApplyDetail(@RequestParam("id") Long id) {

        return remoteProjectApplyFeignApi.projectApplyDetail(id);
    }
    /**
     * 视频监控设置  查看
     *
     * @param projectId 视频监控设置  查看
     * @return ResponseData<PaginationData<ProjectApplyResponse>>
     */
    @ApiOperation(value = "视频监控设置  查看", nickname = "视频监控设置  查看")
    @GetMapping (value = "/view")
    ResponseData<ProjectApplyResponse> view(@RequestParam("projectId") Long projectId) {

        return remoteProjectApplyFeignApi.view(projectId);
    }
    /**
     * 获取 项目免装申请 token
     *
     * @return ResponseData<String>
     */
    @ApiOperation(value = "获取 项目免装申请 token", nickname = "获取 项目免装申请 token")
    @PostMapping(value = "/business-token")
    ResponseData<String> getBusinessToken(){
        return remoteProjectApplyFeignApi.getBusinessToken();
    }
    /**
     * 根据传入的企业组织id获取项目列表
     *
     * @param hrOrganizationId
     * @return
     */
    @ApiOperation(httpMethod = "GET", value = "根据传入的企业组织id和当前人获取项目列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "hrOrganizationId", value = "企业组织id", dataType = "Long", dataTypeClass = Long.class),
    })
    @GetMapping(value = "/getQueryProjectBasicListByHrOrganizationIdAndPerson")
    ResponseData<List<ProjectBasicResponse>> getQueryProjectBasicListByHrOrganizationIdAndPerson(@RequestParam("hrOrganizationId") Long hrOrganizationId){
        return remoteProjectApplyFeignApi.getQueryProjectBasicListByHrOrganizationIdAndPerson(hrOrganizationId);
    }

}
